<template>
	<view>
		
		<view class="">
			
			<view class="item"  v-for="(item, index) in data" :key="index">
				<view class="content" >
					
				<view class="son">
					{{item.name}}
				  </view>
				  
				  <view class="son">
				  地址:{{item.address}}
				    </view>
				
				<view class="detail">
					<view @click="del(item)" class="button-tag">
						删除
					</view>
					<view @click="edit(item)" class="button-tag">
						修改
					</view>
			</view>
			
	
			
					
				</view>
			</view>
		</view>
		
		<view class="bt">
			<u-button type="primary" @click="add">添加企业</u-button>
		</view>
		<u-toast ref="uToast"></u-toast>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				
				data:[
				],
				
			}
		},
		methods: {
			getAllcompany(){
				var that=this
				this.api.get("/company/findMyCompany/"+this.$store.state.userId, {
					
				}).then(res => {
					console.log(res.data)
					that.data = res.data
					console.log(res);
				})
			},
			add(){
				uni.navigateTo({
					url:"/pages/bossregister/bossregister"
				})
			},
			edit(item) {
				uni.navigateTo({
					url: "/pages/bossregister/bossregister?id="+item.id
				})
			},
			del(item) {
				var that = this
				uni.showModal({
					title: '警告',
					content: '是否确认删除',
					success: function(res) {
						if (res.confirm) {
							console.log('用户点击确定');
							that.api.get("/company/delMyCompany/" + item.id, {}).then(res => {
								console.log(res);
								that.$refs.uToast.show({
										duration:1000,
									type: 'default',
									title: '提示',
									message: res.mes,
									iconUrl: 'https://cdn.uviewui.com/uview/demo/toast/default.png'
								})
								
								if(item.id==that.$store.state.myCompanyId ){
									uni.navigateTo({
										url:"/pages/login/login"
									})
								}else{
										that.getAllcompany()
								}
								
								
								
								
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
		
		},
		
		onShow() {
			this.getAllcompany()
		},
		
	}
</script>

<style lang="scss" scoped>
	.bottom-buttons {
		margin-top: 10rpx;
		display: flex;
		justify-content: right;
		align-items: center;
	
	}
	
	.button-tag {
		margin-left: 40rpx;
		height: 30px;
		line-height: 30px;
		padding: 0 20px;
		border-radius: 15px;
		color: #A5A5A5;
		border: 1px solid #EDEDED;
	}
	.detail{
		display: flex;
	}
.top{
	height: 50px;
    background-color: #e2e4ee;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
}
.content{
	background-color: #FFFFFF;
			padding: 20rpx;
			border-radius: 15rpx;
			margin: 15rpx;
}
.son{
		margin: 20rpx;
}
.info{
	margin: 15rpx;
}
.item{
	
}
.bt{
	width: 90%;
	margin: 20rpx auto;
}
</style>
